$(function() {
//	alert('11');
	bannerCon();
	choseCon();
	goodCoup();
	
//	$('.wen').hide()
	 Handlebars.registerHelper('if', function(v1, v2, opts) {
        if(v1 <= v2)
            return opts.fn(this);
        else
            return opts.inverse(this);
    });
})
//轮播图
//function bannerCon() {
//	 //轮播模板
//  var jpbannerTpl = $('#banner-template').html();
//  var jpbannerCmp = Handlebars.compile(jpbannerTpl);
//	$.ajax({
//		url: C.interface.jdbanner,
//		type: 'get',
//		dataType: 'json',
//		data:{},
//		success: function(data) {
////			console.log(data)
//			if(data.code == "10000"){
//				$("#bannerCon").html(jpbannerCmp(data.data));
//			}
//		}
//	})
//}

function bannerCon(){
	$.ajax({
		url: C.interface.jdbanner,
		type: 'get',
		dataType: 'json',
		data:{},
		success: function(data) {
//			console.log(data)
			if(data.code == "10000"){
//				$("#bannerCon").html(jpbannerCmp(data.data));
				var a = data.data
//				console.log(a)
				var html = ''
				for(i in a){
					html += `<div class="swiper-slide"><img src="${a[i].img}"></div>`
				}
				$('.swiper-wrapper').html(html);
				
				var swiper = new Swiper('.swiper-container', {  
                    pagination: '.swiper-pagination',  
                    slidesPerView: 'auto',  
                    paginationClickable: true,  
                    spaceBetween: 0  
                }); 
				
			}
		}
	})
}


//商品精选
function  choseCon(){
	$(".btnImagesTopp").hide()
	 var choiseTmpl = $('#conter-template').html();
 	 var choisepage = Handlebars.compile(choiseTmpl);
	$.ajax({
		url: C.interface.choisegood,
		type: 'get',
		dataType: 'json',
		data:{
			goodsType:"jing"
			},
		success: function(data) {
			if(data.code == "10000"){
				$(".goodsContent").click(function(){
					var id = $(this).attr("data_id");
					window.location.href="goodsDetails.html?id="+id
				});
				$('#choiseshop').html(choisepage(data.data.list));
				
//				console.log(data.data.list);
				
				/* 商品模块hover显示按钮 */
//				$(".goodsContent").mouseover(function(){
//					$(this).find(".btnImagesTop").show();
////					alert($('.fuzhi').length)
//				});

				$(".goodsContent").mouseover(function(){
					$(this).find(".btnImagesTop").show();
				});
				$(".goodsContent").mouseout(function(){
					$(this).find(".btnImagesTop").hide();
				});
 					

					$('.fuzhi').on("mouseover",function(){
					   var index = $('.fuzhi').index($(this));
					   $('.btnImagesTopp').eq(index).show();
					})
					$('.fuzhi').on("mouseleave",function(){
					   var index = $('.fuzhi').index($(this));
					   $('.btnImagesTopp').eq(index).hide();
					})
					
					
//		             鼠标经过下标一直是0
//		            $('.fuzhi').mouseover(function(){
//		                var index = $(this).index()
//		                alert(index)
//		                $('.btnImagesTopp').eq(index).show()
//		            })
//		            
//		             $('.fuzhi').mouseleave(function(){
//		                var index = $(this).index()
//		                $('.btnImagesTopp').eq(index).hide()
//		            })
		             
//		             $(".btn-copyLink").click(function(event){
//		             	$(".btn-copyLink").qtip({
//					content:{  
//              		text:function (){
//              			var str = $(this).attr("id");
//              			
//              			var arr=new Array();
//							arr = str.split(',');
//							var img =  arr[0];
//							var goodsName =  arr[1];
//							var price =  arr[2];
//							var conPrice =  arr[3];
//							var linkUrl =  arr[4];
//							var skUrl =  'http://item.jd.com'+arr[5]+'/.html';
//              			var con = '<img class="goodsImages" width="120px" src="'+img+'" alt="..."><p>'+goodsName+'</p><p>京东价：'+price+'元</p><p>券后价：'+conPrice+'元</p>'+linkUrl+'<p>领券：</p><p></p><p>抢购：</p>'+
//              			'<p>'+ skUrl +'</p>'
//              			return con;
//              		}
//              	}
//					
//					/*content: '<img class="goodsImages" width="120px" src="'+img+'" alt="..."><p>【买2送1 国妆特证】【一喷一抹 30天祛味断根】植物草本萃取，天然成分不过敏不伤肤！</p><p>芊茗草狐臭液喷剂30天根治狐臭</p><p>京东价：48元</p><p>券后价：29元</p><p>领券：</p><p>http://coupon.m.jd.com/coupons/show.action?key=ce63374f6522472584b0c8b0acc3e63d&roleId=10558331&to=mall.jd.com/index-143672.html</p><p>抢购：</p><p>\rhttp://item.jd.com/21590088027.html</p>',*/
//				})
//		             	
//		             })
				
				/*拼接houver显示复制链接*/
				
				$(".btn-copyLink").qtip({
					content:{  
                		text:function (){
                			var str = $(this).attr("id");
                			
                			var arr=new Array();
							arr = str.split(',');
							var img =  arr[0];
							var goodsName =  arr[1];
							var price =  arr[2];
							var conPrice =  arr[3];
							var linkUrl =  arr[4];
							var skUrl =  'http://item.jd.com'+arr[5]+'/.html';
                			var con = '<img class="goodsImages" width="120px" src="'+img+'" alt="..."><p>'+goodsName+'</p><p>京东价：'+price+'元</p><p>券后价：'+conPrice+'元</p>'+linkUrl+'<p>领券：</p><p></p><p>抢购：</p>'+
                			'<p>'+ skUrl +'</p>'
                			return con;
                		}
                	}
					/*content: '<img class="goodsImages" width="120px" src="'+img+'" alt="..."><p>【买2送1 国妆特证】【一喷一抹 30天祛味断根】植物草本萃取，天然成分不过敏不伤肤！</p><p>芊茗草狐臭液喷剂30天根治狐臭</p><p>京东价：48元</p><p>券后价：29元</p><p>领券：</p><p>http://coupon.m.jd.com/coupons/show.action?key=ce63374f6522472584b0c8b0acc3e63d&roleId=10558331&to=mall.jd.com/index-143672.html</p><p>抢购：</p><p>\rhttp://item.jd.com/21590088027.html</p>',*/
				}); 
				var clipboard = new Clipboard('.btn-copyLink');
			    clipboard.on('success', function(e) {
//			        console.log(e);
			        
			    });
			
			    clipboard.on('error', function(e) {
//			        console.log(e);
			    });
			   
				
				$(".extdenbut").click(function(){
					
					var token = localStorage.getItem('token');
					//	console.log(token)
						
					if (token != "" && token != null){
						$(".goodsContent").unbind()
			   		var id = $(this).attr("extend_id");
//					   var url = window.location.href.replace('index.html','html/')
//					   var url = url.split('?')[0]
//			   		 window.location.href = "/ddt/templates/back/chainTool/chainTool.html?id="+id
					   window.location.href = "html/back/chainTool/chainTool.html?id="+id
					   
//					   window.location.href =  window.location.href + '../../html/back/chainTool/offerChainTool.html?id='+id
//						console.log(window.location.href)
					}else{
						window.location.href = 'html/login.html'
					}
					
			   		 
			   })
				
				
				$(".lian").click(function(){
					var url = window.location.pathname; 
					var token = localStorage.getItem('token');
					//	console.log(token)
						
					if (token != "" && token != null){
					
//						var url = window.location.href.replace("index.html",'')
			window.location.href = "html/back/chainTool/chainTool.html"
						
					}else{
						window.location.href = 'html/login.html'
					}
					
			   		 
			   })
			}
		}
	})	
}
//商品优惠券
var bbb = []
function  goodCoup(){
	
//	$(".btnImagesToppp").hide()
	 var coupTmpl = $('#coupngood-template').html();
 	 var couPage = Handlebars.compile(coupTmpl);
   	 
	$.ajax({
		url: C.interface.choisegood,
		type: 'get',
		dataType: 'json',
		data:{
			orderType:"couponMoneyDesc"
		},
		success: function(data) {
			bbb = data.data.list
//			console.log(bbb)
			if(data.code == "10000"){
				$('#coupngood').html(couPage(data.data.list));
//				$(".goodsContent").click(function(){
//				   
//					var id = $(this).attr("data_id");
//					// alert(2)
//					window.location.href="html/goodsDetails.html?id="+id
//				});
				$(".caption").click(function(){
				   
					var id = $(this).attr("data_id");
					// alert(2)
					window.location.href="html/goodsDetails.html?id="+id
				});
				
				$(".goodsImages").click(function(){
				   
					var id = $(this).attr("data_id");
					// alert(2)
					window.location.href="html/goodsDetails.html?id="+id
				});
				
				/* 商品模块hover显示按钮 */
				$(".goodsContent").mouseover(function(){
					$(this).find(".btnImagesTop").show();
				});
				$(".goodsContent").mouseout(function(){
					$(this).find(".btnImagesTop").hide();
				});
				
				$('.copybut').on("mouseover",function(){
					   var index = $('.copybut').index($(this));
					   $('.btnImagesToppp').eq(index).show();
					})
				$('.copybut').on("mouseleave",function(){
					var index = $('.copybut').index($(this));
					$('.btnImagesToppp').eq(index).hide();
				})
				
				/*拼接houver显示复制链接*/
				$(".btn-copyLink").qtip({ 
					content:{  
                		text:function (){
                			var str = $(this).attr("id");
                			var arr=new Array();
							arr = str.split(',');
							var img =  arr[0];
							var goodsName =  arr[1];
							var price =  arr[2];
							var conPrice =  arr[3];
							var linkUrl =  arr[4];
							var skUrl =  'http://item.jd.com'+arr[5]+'/.html';
                			var con = '<img class="goodsImages" width="120px" src="'+img+'" alt="..."><p>'+goodsName+'</p><p>京东价：'+price+'元</p><p>券后价：'+conPrice+'元</p>'+linkUrl+'<p>领券：</p><p></p><p>抢购：</p>'+
                			'<p>'+ skUrl +'</p>'
                			return con;
                		}
                	}
					/*content: '<img class="goodsImages" width="120px" src="'+img+'" alt="..."><p>【买2送1 国妆特证】【一喷一抹 30天祛味断根】植物草本萃取，天然成分不过敏不伤肤！</p><p>芊茗草狐臭液喷剂30天根治狐臭</p><p>京东价：48元</p><p>券后价：29元</p><p>领券：</p><p>http://coupon.m.jd.com/coupons/show.action?key=ce63374f6522472584b0c8b0acc3e63d&roleId=10558331&to=mall.jd.com/index-143672.html</p><p>抢购：</p><p>\rhttp://item.jd.com/21590088027.html</p>',*/
				})
				
				var clipboard = new Clipboard('.copybut');
			    clipboard.on('success', function(e) {
//			        console.log(e);
			       
			    });
			
			    clipboard.on('error', function(e) {
//			        console.log(e);
			    });
				
				//立即推广的按钮、
				$(".vocherBut").click(function(){
					
					var token = localStorage.getItem('token');
					//	console.log(token)
						
					if (token != "" && token != null){
						$(".goodsContent").unbind();
						var id = $(this).attr('vouchId');
						window.location.href = "html/back/chainTool/chainTool.html?id="+id
					}else{
						window.location.href = 'html/login.html'
					}
					
					 
				})
			}
		}
		
	})

}


$('.jiazai').click(function(){
	window.location.href = 'html/newRealTime.html'
	
})

//$(".fen span").click(function () {
//  var aa = $(this).text()
//  var url = encodeURI("html/seach.html?searchVal="+aa);
//  window.location.href = url;
//})




var menuTmpl = $('#menu-template').html();
	var menuPage = Handlebars.compile(menuTmpl);
	$.ajax({
		url: C.interface.categoryInter,
		type: 'get',
		dataType: 'json',
		data: {},
		success: function(data) {
			if(data.code == "10000") {
				$("#menulist").html(menuPage(data.data));
				
				$("#menulist .aa").click(function() {
					var categoryId = $(this).attr("categoryId");
					var url = encodeURI("html/newRealTime.html?categoryId="+categoryId)
					window.location.href = url;
				});

					$('.geng').click(function(){
						window.location.href = './html/newRealTime.html'
					})
				
			}
		}
	})
	
$('.tiao').click(function(){
				window.location.href = 'http://chat56.live800.com/live800/chatClient/chatbox.jsp?companyID=944015&configID=155782&jid=9694995927'
			})

var myDate = new Date();
			//获取当前年
			var year=myDate.getFullYear();
			$('.shi').text(year)
			//		QQ群链接
			$('.ruanjain').click(function(){
				window.location.href ='https://jq.qq.com/?_wv=1027&k=5EP8Afe'
			})
			$('.guanfang').click(function(){
				window.location.href ='https://jq.qq.com/?_wv=1027&k=5sOPc0B'
			})